package asionreachel.cn.smarthomedemo.widget.filter;

import android.content.Context;
import android.content.res.ColorStateList;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.TextView;

import asionreachel.cn.smarthomedemo.R;
import asionreachel.cn.smarthomedemo.utils.Mlog;


/**
 * Created by Simon(lyd) on 2016/11/9 20:44.
 * 描述：点击用textview
 */

public class FilterTextView extends TextView {

    private int colorTrue, colorFalse;

    public FilterTextView(Context context) {
        super(context);
    }

    public FilterTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FilterTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        colorTrue = ContextCompat.getColor(getContext(), R.color.colorBgGray);
        colorFalse = ContextCompat.getColor(getContext(), R.color.colorLineBlack);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        switch (event.getActionMasked()) {

            case MotionEvent.ACTION_DOWN:
                /** 设置滤镜 */
                setFilter();
                break;
            case MotionEvent.ACTION_UP:
                /** 传递点击 */
                performClick();
            case MotionEvent.ACTION_CANCEL:
                /** 删除滤镜 */
                removeFilter();
                break;
            default:
                break;
        }
        return true;
    }


    /**
     * 设置滤镜
     */
    private void setFilter() {

        Mlog.e("设置滤镜");
        ColorStateList colors = getContext().getResources().getColorStateList(R.color.colorLineBlack);
        this.setTextColor(colors);
    }

    /**
     * 清除滤镜
     */
    private void removeFilter() {
        Mlog.e("清除滤镜");
        ColorStateList colors = getContext().getResources().getColorStateList(R.color.colorBgGray);
        this.setTextColor(colors);
    }
}
